package cn.laniakea.solrj;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.SolrParams;
import org.junit.Test;

public class SolrjSuper {
    @Test
    public void testSort() throws SolrServerException {
        //创建solr服务对象
        HttpSolrServer solrServer=new HttpSolrServer("http://localhost:8080/solr/core1");
        //查询对象
        SolrQuery query=new SolrQuery("title:手机");
        query.setSort("id", SolrQuery.ORDER.desc);
        //执行查询,获取响应
        QueryResponse response = solrServer.query(query);
        SolrDocumentList documentList = response.getResults();
        for (SolrDocument solrDocument : documentList) {
            System.out.println("id"+solrDocument.get("id")+",title:"+solrDocument.get("title")+
            ",price:"+solrDocument.get("price"));

        }
    }
    @Test
    public void testPage(){
        //创建solr服务对象
        HttpSolrServer solrServer=new HttpSolrServer("http://localhost:8080/solr/core1");
        //查询对象
        SolrQuery query=new SolrQuery("title:手机");
       
        //执行查询,获取响应
        QueryResponse response = solrServer.query(query);
        SolrDocumentList documentList = response.getResults();
        for (SolrDocument solrDocument : documentList) {
            System.out.println("id"+solrDocument.get("id")+",title:"+solrDocument.get("title")+
                    ",price:"+solrDocument.get("price"));

        }
    }
    @Test
    public void testHL(){

    }

}
